package com.groupbuying.currency.producer.utils;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

/**
 * @author zmlmagic
 * @date 2019/4/18 5:30 PM
 * @company 蒙泰互联网公司
 * @des object与map转换
 **/
public class ObjectUtils {
    public static Map<String, Object> objectToMap(Object obj) {
        try {
            Map<String, Object> map = new HashMap<String, Object>();
            Field[] fields = obj.getClass().getDeclaredFields();
            for (Field field : fields) {
                field.setAccessible(true);
                map.put(field.getName(), field.get(obj));
            }
            return map;
        } catch (Exception e) {
            return new HashMap<>();
        }

    }
}
